package com.guigu.handler.impl;

import cn.hutool.core.bean.BeanUtil;
import com.guigu.annotation.SubjectInfoType;
import com.guigu.domain.dto.SubjectInfoDTO;
import com.guigu.domain.entity.SubjectInfo;
import com.guigu.domain.entity.SubjectMultiple;
import com.guigu.domain.entity.SubjectRadio;
import com.guigu.domain.enums.IsDeletedFlagEnum;
import com.guigu.domain.enums.SubjectInfoEnum;
import com.guigu.handler.SubjectInfoHandler;
import com.guigu.service.ISubjectMultipleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @description: 多选题
 * @author: JZC
 * @create: 2024-06-07 00:20
 **/
@Component("multipleTypeSubjectInfoHandler")
@SubjectInfoType(type = SubjectInfoEnum.MULTIPLE_TYPE)
@Slf4j
public class MultipleTypeSubjectInfoHandler implements SubjectInfoHandler {

    @Resource
    private ISubjectMultipleService subjectMultipleService;
    @Override
    public void add(SubjectInfoDTO subjectInfoDTO) {
        log.info("多选题添加逻辑代码...");
        //将选项放入集合里面
        List<SubjectMultiple> subjectRadioList = new LinkedList<>();
        subjectInfoDTO.getOptionList().forEach(option->{
            SubjectMultiple subjectMultiple = BeanUtil.toBean(option, SubjectMultiple.class);
            subjectMultiple.setSubjectId(subjectInfoDTO.getId());
            subjectMultiple.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            //添加到集合
            subjectRadioList.add(subjectMultiple);
        });
        subjectMultipleService.saveBatch(subjectRadioList);
    }
}
